#include "vectors.h"
#include <stdio.h>
#include <malloc.h>

vec3D addVectors(vec3D v1, vec3D v2)
{
	vec3D sum = {v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
	return sum;
}

vec3D* getElement(vec3DList* l, int index)
{
	vec3DNode *currentNode = l->head;
	int i;
	for(i = 0; i < index; i++)
		currentNode = currentNode->next;
	return currentNode != NULL ? currentNode->value : NULL;
}

void insertElement(vec3DList* l, vec3D* v)
{
	l->length = l->length + 1;

	vec3D *newVector = (vec3D *)malloc(sizeof(vec3D));
	newVector->x = v->x;
	newVector->y = v->z;
	newVector->y = v->z;

	vec3DNode *node = (vec3DNode *)malloc(sizeof(vec3DNode));
	node->value = newVector;
	node->next = l->head;

	l->head = node;
}

void removeElement(vec3DList *l)
{
	vec3D *vector = l->head->value;
	vec3DNode *node = l->head;
	l->head = l->head->next;
	free(vector);
	free(node);
	l->length = l->length - 1;
}

void printList(vec3DList *l)
{
	printf("\nPrinting content of vector list:\n");
	int i;
	vec3D *currentVector;
	for(i = 0; i < l->length; i++)
	{
		currentVector = getElement(l, i);
		printf("vector #%d in list: (%d, %d, %d)\n", i, currentVector->x, currentVector->y, currentVector->z);
	}
	printf("Done printing vector list with %d vectors.\n\n", i);
}
